package com.stwitinc.redmine.dao.medicine;

import java.sql.SQLException;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.stwitinc.Util;
import com.stwitinc.data.model.stwnews.PackageInsert;
import com.stwitinc.redmine.dao.DAO;
import com.stwitinc.redmine.dao.MedicineDAO;

public class MedicineDAOImpl extends DAO implements MedicineDAO
{
	@Override
	public JSONObject getPackageInsertById(int medicineId) throws SQLException {
		final PackageInsert rec = new PackageInsert();
		rec.setMedicineId(String.valueOf(medicineId));
		return rec.selectFirst(this);
	}

	@Override
	public JSONArray getPackageInsertList(List<Integer> medicineIdList) throws SQLException {
		if (medicineIdList == null || medicineIdList.size() == 0) {
			return new JSONArray();
		}
		String sql = "select medicine_id,generic_name,trade_name,vendor,composition,indications from package_insert where medicine_id in (" + Util.join(",", medicineIdList) + ")";
		JSONObject data = executeQuery(sql);
		return data.getJSONArray("records");
	}

	@Override
	public JSONArray getPackageInsertSummary() throws SQLException {
		String sql = "select medicine_id,generic_name,generic_name_py,trade_name,trade_name_py from package_insert";
		JSONObject data = executeQuery(sql);
		return data.getJSONArray("records");
	}

}
